using System.Linq;
using NHibernate.Linq;
using Ornament.MemberShip.Permissions;
using Ornament.NHibernates;

namespace Ornament.MemberShip.Dao.NHibernateImple
{
    public class MemberShipFactory : IMemberShipFactory
    {
        #region IMemberShipFactory Members

       /* public IQueryable<Profile> Profiles
        {
            get
            {
                IQueryable<Profile> result = SessionManager.Instance.CurrentSession.Query<Profile>();
                return result;
            }
        }*/

        //public IQueryable<ResourceInfo> Resources
        //{
        //    get { return CreateResourceDao().ResourceInfos; }
        //}

        //public IQueryable<T> GetResources<T>() where T : ResourceInfo
        //{
        //    return SessionManager.Instance.CurrentSession.Query<T>();
        //}

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IUserDao CreateUserDao()
        {
            return CreateUserDao(true);
        }

        public IUserDao CreateUserDao(bool useGlobalConnection)
        {
            return new UserDao(useGlobalConnection);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IUserGroupDao CreateUserGroupDao()
        {
            return new UserGroupDao();
        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IRoleDao CreateRoleDao()
        {
            return new RoleDao();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IMemberDao CreateMemberDao()
        {
            return new MemberDao();
        }


        public IQueryable<User> Users
        {
            get { return CreateUserDao().Users; }
        }

        public IQueryable<Role> Roles
        {
            get { return CreateRoleDao().Roles; }
        }

        public IQueryable<UserGroup> UserGroups
        {
            get { return CreateUserGroupDao().UserGroups; }
        }


        public IQueryable<Permission> Permissions
        {
            get { return CreatePermissionDao().Permissions; }
        }


        public IPermissionDao CreatePermissionDao()
        {
            return PermissionDao(true);
        }

        public IPermissionDao PermissionDao(bool useGlobalConnection)
        {
            return new PermissionDao(useGlobalConnection);
        }

        public IResourceDao CreateResourceDao()
        {
            return new ResourceDao();
        }

        #endregion
    }
}